import * as types from '../types'
import  api from '../../fetch/api'

const state = {
	bannerdata: [], //首页banner
	column: [], //首页三个大分类
	specialdata: [], //精选专场
	ad: [], //广告
	lunbostatus:false,
	getshortHouseListdata: [], //短租推荐房源
	getlongHouseListdata: [], //长租推荐房源
}
const actions = {
	getHomeInfo({dispatch,commit}, data) {
		api.GetHome(data)
		.then(res => {
			let ajaxdata = res.result;
			if(ajaxdata.carousel.length == 0) {
				commit(types.HOME_BANNER_DATA, false)
			} else {
				commit(types.HOME_BANNER_DATA, ajaxdata.carousel)
			}
			if(ajaxdata.column.length == 0) {
				commit(types.HOME_COLUMN_DATA, false)
			} else {
				commit(types.HOME_COLUMN_DATA, ajaxdata.column)
			}
			if(ajaxdata.special.length == 0) {
				commit(types.HOME_SPECIAL_DATA, false)
			} else {
				commit(types.HOME_SPECIAL_DATA, ajaxdata.special)
			}
			if(ajaxdata.ad.length == 0) {
				commit(types.HOME_AD_DATA, false)
			} else {
				commit(types.HOME_AD_DATA, ajaxdata.ad)
			}
		})
	},
	getRecommendInfo({commit}, data) {
			if (data[0]==undefined) {
			commit(types.HOME_LONGLIST_DATA, false)
			return;
			}
			commit(types.HOME_SHORTLIST_DATA, data[0])
			if (data[1]==undefined) {
			commit(types.HOME_LONGLIST_DATA, false)
			return;
			}
			commit(types.HOME_LONGLIST_DATA, data[1])
			commit(types.HOME_LUNBO_STATUS, true)
	},
}

const getters = {
	bannerdata: state => state.bannerdata, //首页banner
	column: state => state.column, //首页三个大分类
	specialdata: state => state.specialdata, //精选专场
	ad: state => state.ad, //广告
	lunbostatus: state => state.lunbostatus, //短租推荐房源
	getshortHouseListdata: state => state.getshortHouseListdata, //短租推荐房源
	getlongHouseListdata: state => state.getlongHouseListdata, //长租推荐房源
}

const mutations = {
	[types.HOME_BANNER_DATA](state, res) {
		state.bannerdata = res
	},
	[types.HOME_COLUMN_DATA](state, res) {
		state.column = res
	},
	[types.HOME_SPECIAL_DATA](state, res) {
		state.specialdata = res
	},
	[types.HOME_AD_DATA](state, res) {
		state.ad = res
	},
	[types.HOME_LUNBO_STATUS](state, res) {
		state.lunbostatus = res
	},
	[types.HOME_SHORTLIST_DATA](state, res) {
		state.getshortHouseListdata = res
	},
	[types.HOME_LONGLIST_DATA](state, res) {
		state.getlongHouseListdata = res
	},
}

export default {
	state,
	actions,
	getters,
	mutations
}